source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-345.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.083.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4543 1717 1078 298 61 6971 3378 3867 1565 323 6693 5036 4079 2519 1040 5012
17 18 19 20 21 22 23 24 25
3322 2275 4601 4309 7402 5844 5407 7053 6488
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip
[1,] 0.8269473 0.2466224
[2,] 0.6635539 -0.5127185
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
fecha_cnt precip
0.9902213 0.9753982
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:149.0 1st Qu.: 52.00 1st Qu.: 3.00
Median : 6.000 Median :199.0 Median : 98.00 Median :10.00
Mean : 6.448 Mean :201.1 Mean : 99.12 Mean :14.67
3rd Qu.: 9.000 3rd Qu.:256.0 3rd Qu.: 148.00 3rd Qu.:21.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :95.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.00 1st Qu.: -5.6417
Median :0.000000 Median : 0.0000 Median :40.82 Median : -3.1742
Mean :0.000301 Mean : 0.4281 Mean :39.63 Mean : -3.4105
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.05 3rd Qu.: 0.4914
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 247.0
Mean : 419.4
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 69.00
1st Qu.: 9.000 1st Qu.:123.0 1st Qu.: 58.00 1st Qu.: 78.00
Median :11.000 Median :152.0 Median : 85.00 Median : 92.00
Mean : 9.227 Mean :153.7 Mean : 84.87 Mean : 97.12
3rd Qu.:11.000 3rd Qu.:189.0 3rd Qu.: 115.00 3rd Qu.:110.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :177.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -8.411
Median :0 Median : 0.000 Median :42.43 Median : -4.488
Mean :0 Mean : 2.297 Mean :41.23 Mean : -4.677
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 108.0
Mean : 372.9
3rd Qu.: 370.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:132.0 1st Qu.: 32.00 1st Qu.: 6.00
Median :3.000 Median :166.0 Median : 67.00 Median :14.00
Mean :3.138 Mean :165.2 Mean : 66.55 Mean :18.36
3rd Qu.:4.000 3rd Qu.:201.0 3rd Qu.: 100.00 3rd Qu.:26.00
Max. :7.000 Max. :352.0 Max. : 213.00 Max. :95.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.6156
Median :0.000000 Median : 0.0000 Median :40.96 Median : -2.9553
Mean :0.000477 Mean : 0.8945 Mean :40.00 Mean : -3.2067
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4914
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 258.0
Mean : 435.1
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 69.00
1st Qu.: 9.000 1st Qu.:123.0 1st Qu.: 58.00 1st Qu.: 78.00
Median :11.000 Median :152.0 Median : 85.00 Median : 92.00
Mean : 9.227 Mean :153.7 Mean : 84.87 Mean : 97.12
3rd Qu.:11.000 3rd Qu.:189.0 3rd Qu.: 115.00 3rd Qu.:110.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :177.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -8.411
Median :0 Median : 0.000 Median :42.43 Median : -4.488
Mean :0 Mean : 2.297 Mean :41.23 Mean : -4.677
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 108.0
Mean : 372.9
3rd Qu.: 370.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 5.000 Min. :-24.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:177.0 1st Qu.: 81.0 1st Qu.: 1.00
Median : 9.000 Median :238.0 Median : 132.0 Median : 7.00
Mean : 8.924 Mean :227.9 Mean : 123.5 Mean :11.92
3rd Qu.:11.000 3rd Qu.:282.0 3rd Qu.: 170.0 3rd Qu.:17.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :68.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:37.96 1st Qu.: -5.6492
Median :0.0000000 Median : 0.0000 Median :40.66 Median : -3.4503
Mean :0.0001689 Mean : 0.0793 Mean :39.36 Mean : -3.5630
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 0.4914
Max. :3.0000000 Max. :338.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 35.0
Median : 192.0
Mean : 407.6
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:134.0 1st Qu.: 31.00 1st Qu.: 6.00
Median :3.000 Median :169.0 Median : 66.00 Median :12.00
Mean :3.128 Mean :167.9 Mean : 66.89 Mean :13.92
3rd Qu.:4.000 3rd Qu.:204.0 3rd Qu.: 101.00 3rd Qu.:21.00
Max. :6.000 Max. :342.0 Max. : 213.00 Max. :39.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.5975
Median :0.000000 Median : 0.0000 Median :40.87 Median : -2.9056
Mean :0.000535 Mean : 0.4659 Mean :39.82 Mean : -3.1711
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.00 3rd Qu.: 0.4914
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 425.4
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-50.0 Min. :-115.00 Min. :39.00 Min. :0
1st Qu.:2.000 1st Qu.:118.0 1st Qu.: 42.00 1st Qu.:44.00 1st Qu.:0
Median :3.000 Median :146.0 Median : 68.00 Median :50.00 Median :0
Mean :3.219 Mean :143.4 Mean : 63.73 Mean :54.52 Mean :0
3rd Qu.:5.000 3rd Qu.:176.0 3rd Qu.: 93.00 3rd Qu.:62.00 3rd Qu.:0
Max. :7.000 Max. :352.0 Max. : 210.00 Max. :95.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -6.0556 1st Qu.: 47.0
Median : 0.000 Median :42.43 Median : -3.7994 Median : 251.0
Mean : 4.385 Mean :41.40 Mean : -3.4961 Mean : 514.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.4914 3rd Qu.: 582.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 69.00
1st Qu.: 9.000 1st Qu.:123.0 1st Qu.: 58.00 1st Qu.: 78.00
Median :11.000 Median :152.0 Median : 85.00 Median : 92.00
Mean : 9.227 Mean :153.7 Mean : 84.87 Mean : 97.12
3rd Qu.:11.000 3rd Qu.:189.0 3rd Qu.: 115.00 3rd Qu.:110.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :177.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -8.411
Median :0 Median : 0.000 Median :42.43 Median : -4.488
Mean :0 Mean : 2.297 Mean :41.23 Mean : -4.677
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 108.0
Mean : 372.9
3rd Qu.: 370.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 5.000 Min. :-24.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:177.0 1st Qu.: 81.0 1st Qu.: 1.00
Median : 9.000 Median :238.0 Median : 132.0 Median : 7.00
Mean : 8.924 Mean :227.9 Mean : 123.5 Mean :11.92
3rd Qu.:11.000 3rd Qu.:282.0 3rd Qu.: 170.0 3rd Qu.:17.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :68.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:37.96 1st Qu.: -5.6492
Median :0.0000000 Median : 0.0000 Median :40.66 Median : -3.4503
Mean :0.0001689 Mean : 0.0793 Mean :39.36 Mean : -3.5630
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 0.4914
Max. :3.0000000 Max. :338.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 35.0
Median : 192.0
Mean : 407.6
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:134.0 1st Qu.: 31.00 1st Qu.: 6.00
Median :3.000 Median :169.0 Median : 66.00 Median :12.00
Mean :3.128 Mean :167.9 Mean : 66.89 Mean :13.92
3rd Qu.:4.000 3rd Qu.:204.0 3rd Qu.: 101.00 3rd Qu.:21.00
Max. :6.000 Max. :342.0 Max. : 213.00 Max. :39.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.5975
Median :0.000000 Median : 0.0000 Median :40.87 Median : -2.9056
Mean :0.000535 Mean : 0.4659 Mean :39.82 Mean : -3.1711
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.00 3rd Qu.: 0.4914
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 425.4
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-50.0 Min. :-115.00 Min. :39.00 Min. :0
1st Qu.:2.000 1st Qu.:118.0 1st Qu.: 42.00 1st Qu.:44.00 1st Qu.:0
Median :3.000 Median :146.0 Median : 68.00 Median :50.00 Median :0
Mean :3.219 Mean :143.4 Mean : 63.73 Mean :54.52 Mean :0
3rd Qu.:5.000 3rd Qu.:176.0 3rd Qu.: 93.00 3rd Qu.:62.00 3rd Qu.:0
Max. :7.000 Max. :352.0 Max. : 210.00 Max. :95.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -6.0556 1st Qu.: 47.0
Median : 0.000 Median :42.43 Median : -3.7994 Median : 251.0
Mean : 4.385 Mean :41.40 Mean : -3.4961 Mean : 514.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.4914 3rd Qu.: 582.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-108.00 Min. : 69.00
1st Qu.: 9.000 1st Qu.:123.0 1st Qu.: 58.00 1st Qu.: 78.00
Median :11.000 Median :152.0 Median : 85.00 Median : 92.00
Mean : 9.227 Mean :153.7 Mean : 84.87 Mean : 97.12
3rd Qu.:11.000 3rd Qu.:189.0 3rd Qu.: 115.00 3rd Qu.:110.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :177.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -8.411
Median :0 Median : 0.000 Median :42.43 Median : -4.488
Mean :0 Mean : 2.297 Mean :41.23 Mean : -4.677
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 32.0
Median : 108.0
Mean : 372.9
3rd Qu.: 370.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. :-17.0 Min. :-80.00 Min. :23.00 Min. :0
1st Qu.: 9.00 1st Qu.:140.0 1st Qu.: 64.00 1st Qu.:29.00 1st Qu.:0
Median :10.00 Median :184.0 Median :100.00 Median :36.00 Median :0
Mean :10.19 Mean :182.7 Mean : 98.63 Mean :38.61 Mean :0
3rd Qu.:11.00 3rd Qu.:226.0 3rd Qu.:138.00 3rd Qu.:46.00 3rd Qu.:0
Max. :12.00 Max. :340.0 Max. :244.00 Max. :68.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.: -5.6614 1st Qu.: 43.3
Median : 0.0000 Median :41.96 Median : -2.9056 Median : 185.0
Mean : 0.3201 Mean :40.98 Mean : -2.9424 Mean : 440.5
3rd Qu.: 0.0000 3rd Qu.:42.89 3rd Qu.: 0.7789 3rd Qu.: 617.0
Max. :338.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 5.000 Min. :-24.0 Min. :-110.0 Min. : 0.000
1st Qu.: 7.000 1st Qu.:192.0 1st Qu.: 88.0 1st Qu.: 1.000
Median : 9.000 Median :249.0 Median : 139.0 Median : 4.000
Mean : 8.672 Mean :236.9 Mean : 128.4 Mean : 6.587
3rd Qu.:10.000 3rd Qu.:289.0 3rd Qu.: 176.0 3rd Qu.:11.000
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :25.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:37.79 1st Qu.: -5.6492
Median :0.0000000 Median : 0.00000 Median :40.41 Median : -3.4503
Mean :0.0002026 Mean : 0.03115 Mean :39.04 Mean : -3.6869
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 0.3994
Max. :3.0000000 Max. :77.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 35
Median : 192
Mean : 401
3rd Qu.: 656
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:134.0 1st Qu.: 31.00 1st Qu.: 6.00
Median :3.000 Median :169.0 Median : 66.00 Median :12.00
Mean :3.128 Mean :167.9 Mean : 66.89 Mean :13.92
3rd Qu.:4.000 3rd Qu.:204.0 3rd Qu.: 101.00 3rd Qu.:21.00
Max. :6.000 Max. :342.0 Max. : 213.00 Max. :39.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.5975
Median :0.000000 Median : 0.0000 Median :40.87 Median : -2.9056
Mean :0.000535 Mean : 0.4659 Mean :39.82 Mean : -3.1711
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.00 3rd Qu.: 0.4914
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 425.4
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-50.0 Min. :-115.00 Min. :39.00 Min. :0
1st Qu.:2.000 1st Qu.:118.0 1st Qu.: 42.00 1st Qu.:44.00 1st Qu.:0
Median :3.000 Median :146.0 Median : 68.00 Median :50.00 Median :0
Mean :3.219 Mean :143.4 Mean : 63.73 Mean :54.52 Mean :0
3rd Qu.:5.000 3rd Qu.:176.0 3rd Qu.: 93.00 3rd Qu.:62.00 3rd Qu.:0
Max. :7.000 Max. :352.0 Max. : 210.00 Max. :95.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -6.0556 1st Qu.: 47.0
Median : 0.000 Median :42.43 Median : -3.7994 Median : 251.0
Mean : 4.385 Mean :41.40 Mean : -3.4961 Mean : 514.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.4914 3rd Qu.: 582.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-108.00 Min. : 95.0 Min. :0
1st Qu.:1.000 1st Qu.:109.0 1st Qu.: 39.00 1st Qu.:102.0 1st Qu.:0
Median :2.000 Median :127.0 Median : 61.00 Median :110.0 Median :0
Mean :2.305 Mean :127.1 Mean : 59.51 Mean :115.1 Mean :0
3rd Qu.:3.000 3rd Qu.:150.8 3rd Qu.: 83.00 3rd Qu.:126.0 3rd Qu.:0
Max. :6.000 Max. :280.0 Max. : 162.00 Max. :169.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -8.624 1st Qu.: 42.0
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 6.262 Mean :41.43 Mean : -5.887 Mean : 399.5
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2519.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 6.00 Min. : -8.0 Min. :-58.00 Min. :106 Min. :0
1st Qu.:10.00 1st Qu.:125.5 1st Qu.: 64.00 1st Qu.:113 1st Qu.:0
Median :11.00 Median :149.0 Median : 86.00 Median :122 Median :0
Mean :10.85 Mean :151.1 Mean : 85.38 Mean :127 Mean :0
3rd Qu.:12.00 3rd Qu.:181.5 3rd Qu.:111.00 3rd Qu.:138 3rd Qu.:0
Max. :12.00 Max. :326.0 Max. :207.00 Max. :177 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-17.755 Min. : 1.00
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -8.518 1st Qu.: 28.05
Median : 0.0000 Median :42.44 Median : -5.600 Median : 200.00
Mean : 0.9257 Mean :41.23 Mean : -5.237 Mean : 394.77
3rd Qu.: 0.0000 3rd Qu.:43.30 3rd Qu.: -1.913 3rd Qu.: 370.00
Max. :81.0000 Max. :43.57 Max. : 3.035 Max. :2535.00
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. :-17.0 Min. :-80.00 Min. :23.00 Min. :0
1st Qu.: 9.00 1st Qu.:140.0 1st Qu.: 64.00 1st Qu.:29.00 1st Qu.:0
Median :10.00 Median :184.0 Median :100.00 Median :36.00 Median :0
Mean :10.19 Mean :182.7 Mean : 98.63 Mean :38.61 Mean :0
3rd Qu.:11.00 3rd Qu.:226.0 3rd Qu.:138.00 3rd Qu.:46.00 3rd Qu.:0
Max. :12.00 Max. :340.0 Max. :244.00 Max. :68.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.: -5.6614 1st Qu.: 43.3
Median : 0.0000 Median :41.96 Median : -2.9056 Median : 185.0
Mean : 0.3201 Mean :40.98 Mean : -2.9424 Mean : 440.5
3rd Qu.: 0.0000 3rd Qu.:42.89 3rd Qu.: 0.7789 3rd Qu.: 617.0
Max. :338.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. : -7.0 Min. :-69.00 Min. : 69.00 Min. :0
1st Qu.:10.00 1st Qu.:131.0 1st Qu.: 66.00 1st Qu.: 74.00 1st Qu.:0
Median :11.00 Median :164.0 Median : 93.00 Median : 81.00 Median :0
Mean :10.71 Mean :162.1 Mean : 91.97 Mean : 82.69 Mean :0
3rd Qu.:12.00 3rd Qu.:200.0 3rd Qu.:125.00 3rd Qu.: 90.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :105.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.076 1st Qu.: 32.0
Median : 0.000 Median :42.43 Median : -3.831 Median : 98.0
Mean : 1.587 Mean :41.17 Mean : -4.156 Mean : 358.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 361.8
Max. :382.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 5.000 Min. :-24.0 Min. :-110.0 Min. : 0.000
1st Qu.: 7.000 1st Qu.:192.0 1st Qu.: 88.0 1st Qu.: 1.000
Median : 9.000 Median :249.0 Median : 139.0 Median : 4.000
Mean : 8.672 Mean :236.9 Mean : 128.4 Mean : 6.587
3rd Qu.:10.000 3rd Qu.:289.0 3rd Qu.: 176.0 3rd Qu.:11.000
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :25.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:37.79 1st Qu.: -5.6492
Median :0.0000000 Median : 0.00000 Median :40.41 Median : -3.4503
Mean :0.0002026 Mean : 0.03115 Mean :39.04 Mean : -3.6869
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 0.3994
Max. :3.0000000 Max. :77.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 35
Median : 192
Mean : 401
3rd Qu.: 656
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.000
1st Qu.:1.000 1st Qu.:119.0 1st Qu.: 17.00 1st Qu.: 2.000
Median :2.000 Median :156.0 Median : 48.00 Median : 6.000
Mean :2.217 Mean :152.2 Mean : 52.29 Mean : 6.864
3rd Qu.:3.000 3rd Qu.:187.0 3rd Qu.: 83.00 3rd Qu.:10.000
Max. :4.000 Max. :300.0 Max. : 193.00 Max. :23.000
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:37.96 1st Qu.: -5.5975
Median :0.000000 Median : 0.0000 Median :40.41 Median : -2.4831
Mean :0.001044 Mean : 0.3035 Mean :39.01 Mean : -3.4370
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.63 3rd Qu.: 0.4914
Max. :6.000000 Max. :626.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 35.0
Median : 200.0
Mean : 398.4
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-50.0 Min. :-115.00 Min. :39.00 Min. :0
1st Qu.:2.000 1st Qu.:118.0 1st Qu.: 42.00 1st Qu.:44.00 1st Qu.:0
Median :3.000 Median :146.0 Median : 68.00 Median :50.00 Median :0
Mean :3.219 Mean :143.4 Mean : 63.73 Mean :54.52 Mean :0
3rd Qu.:5.000 3rd Qu.:176.0 3rd Qu.: 93.00 3rd Qu.:62.00 3rd Qu.:0
Max. :7.000 Max. :352.0 Max. : 210.00 Max. :95.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -6.0556 1st Qu.: 47.0
Median : 0.000 Median :42.43 Median : -3.7994 Median : 251.0
Mean : 4.385 Mean :41.40 Mean : -3.4961 Mean : 514.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.4914 3rd Qu.: 582.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-108.00 Min. : 95.0 Min. :0
1st Qu.:1.000 1st Qu.:109.0 1st Qu.: 39.00 1st Qu.:102.0 1st Qu.:0
Median :2.000 Median :127.0 Median : 61.00 Median :110.0 Median :0
Mean :2.305 Mean :127.1 Mean : 59.51 Mean :115.1 Mean :0
3rd Qu.:3.000 3rd Qu.:150.8 3rd Qu.: 83.00 3rd Qu.:126.0 3rd Qu.:0
Max. :6.000 Max. :280.0 Max. : 162.00 Max. :169.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -8.624 1st Qu.: 42.0
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 6.262 Mean :41.43 Mean : -5.887 Mean : 399.5
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2519.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :173.0 Min. :0
1st Qu.: 2.000 1st Qu.:115.0 1st Qu.: 53.00 1st Qu.:185.0 1st Qu.:0
Median : 6.000 Median :136.0 Median : 80.00 Median :205.0 Median :0
Mean : 6.328 Mean :151.5 Mean : 84.85 Mean :219.4 Mean :0
3rd Qu.:11.000 3rd Qu.:158.0 3rd Qu.: 97.00 3rd Qu.:231.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0 1st Qu.:40.66 1st Qu.: -8.624 1st Qu.: 82.0
Median : 0 Median :42.24 Median : -8.411 Median : 261.0
Mean : 10 Mean :40.75 Mean : -7.011 Mean : 411.3
3rd Qu.: 0 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.0
Max. :607 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-53.0 Min. :-113.00 Min. : 9.00 Min. :0
1st Qu.:3.000 1st Qu.:151.0 1st Qu.: 52.00 1st Qu.:14.00 1st Qu.:0
Median :4.000 Median :184.0 Median : 83.00 Median :20.00 Median :0
Mean :4.088 Mean :184.4 Mean : 82.27 Mean :21.35 Mean :0
3rd Qu.:5.000 3rd Qu.:220.0 3rd Qu.: 114.00 3rd Qu.:28.00 3rd Qu.:0
Max. :6.000 Max. :342.0 Max. : 213.00 Max. :39.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.86 1st Qu.: -5.5975 1st Qu.: 58.0
Median : 0.0000 Median :41.42 Median : -3.1642 Median : 353.0
Mean : 0.6368 Mean :40.68 Mean : -2.8912 Mean : 453.7
3rd Qu.: 0.0000 3rd Qu.:42.45 3rd Qu.: 0.4914 3rd Qu.: 687.0
Max. :1494.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 6.00 Min. : -8.0 Min. :-58.00 Min. :106 Min. :0
1st Qu.:10.00 1st Qu.:125.5 1st Qu.: 64.00 1st Qu.:113 1st Qu.:0
Median :11.00 Median :149.0 Median : 86.00 Median :122 Median :0
Mean :10.85 Mean :151.1 Mean : 85.38 Mean :127 Mean :0
3rd Qu.:12.00 3rd Qu.:181.5 3rd Qu.:111.00 3rd Qu.:138 3rd Qu.:0
Max. :12.00 Max. :326.0 Max. :207.00 Max. :177 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-17.755 Min. : 1.00
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -8.518 1st Qu.: 28.05
Median : 0.0000 Median :42.44 Median : -5.600 Median : 200.00
Mean : 0.9257 Mean :41.23 Mean : -5.237 Mean : 394.77
3rd Qu.: 0.0000 3rd Qu.:43.30 3rd Qu.: -1.913 3rd Qu.: 370.00
Max. :81.0000 Max. :43.57 Max. : 3.035 Max. :2535.00
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. :-17.0 Min. :-80.00 Min. :23.00 Min. :0
1st Qu.: 9.00 1st Qu.:140.0 1st Qu.: 64.00 1st Qu.:29.00 1st Qu.:0
Median :10.00 Median :184.0 Median :100.00 Median :36.00 Median :0
Mean :10.19 Mean :182.7 Mean : 98.63 Mean :38.61 Mean :0
3rd Qu.:11.00 3rd Qu.:226.0 3rd Qu.:138.00 3rd Qu.:46.00 3rd Qu.:0
Max. :12.00 Max. :340.0 Max. :244.00 Max. :68.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.: -5.6614 1st Qu.: 43.3
Median : 0.0000 Median :41.96 Median : -2.9056 Median : 185.0
Mean : 0.3201 Mean :40.98 Mean : -2.9424 Mean : 440.5
3rd Qu.: 0.0000 3rd Qu.:42.89 3rd Qu.: 0.7789 3rd Qu.: 617.0
Max. :338.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 7.00 Min. : -7.0 Min. :-69.00 Min. : 69.00 Min. :0
1st Qu.:10.00 1st Qu.:131.0 1st Qu.: 66.00 1st Qu.: 74.00 1st Qu.:0
Median :11.00 Median :164.0 Median : 93.00 Median : 81.00 Median :0
Mean :10.71 Mean :162.1 Mean : 91.97 Mean : 82.69 Mean :0
3rd Qu.:12.00 3rd Qu.:200.0 3rd Qu.:125.00 3rd Qu.: 90.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :105.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.076 1st Qu.: 32.0
Median : 0.000 Median :42.43 Median : -3.831 Median : 98.0
Mean : 1.587 Mean :41.17 Mean : -4.156 Mean : 358.5
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 361.8
Max. :382.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :5.000 Min. : 58.0 Min. :-26.0 Min. : 0.000 Min. :0
1st Qu.:6.000 1st Qu.:250.0 1st Qu.:137.0 1st Qu.: 0.000 1st Qu.:0
Median :7.000 Median :283.0 Median :165.0 Median : 2.000 Median :0
Mean :6.847 Mean :279.5 Mean :161.9 Mean : 4.066 Mean :0
3rd Qu.:8.000 3rd Qu.:310.0 3rd Qu.:190.0 3rd Qu.: 6.000 3rd Qu.:0
Max. :8.000 Max. :403.0 Max. :254.0 Max. :24.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.42 1st Qu.: -5.7333 1st Qu.: 33.0
Median : 0.00000 Median :40.30 Median : -3.6781 Median : 148.0
Mean : 0.00273 Mean :38.89 Mean : -3.9267 Mean : 380.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.3664 3rd Qu.: 628.0
Max. :39.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip
Min. : 9.00 Min. :-24.0 Min. :-110.00 Min. : 0.000
1st Qu.: 9.00 1st Qu.:146.0 1st Qu.: 48.00 1st Qu.: 3.000
Median :10.00 Median :199.0 Median : 96.00 Median : 8.000
Mean :10.46 Mean :195.2 Mean : 95.69 Mean : 9.055
3rd Qu.:12.00 3rd Qu.:249.0 3rd Qu.: 144.00 3rd Qu.:15.000
Max. :12.00 Max. :401.0 Max. : 236.00 Max. :25.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.: -5.5975
Median :0.0000000 Median : 0.00000 Median :40.48 Median : -2.9553
Mean :0.0004009 Mean : 0.05897 Mean :39.20 Mean : -3.4523
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 0.4914
Max. :3.0000000 Max. :77.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 261.0
Mean : 421.3
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)